<?php
class ImageGridImage extends DomArObject {
	/**
	 * @orm text
	 */
	public $title;
	/**
	 * @orm plugin DomArImage()
	 * @orm listener afterAdd afterAddImage
	 */
	public $icon;
	/**
	 * @orm plugin SimpleOrder()
	 */
	public $order;
	
	public function afterAddImage() {
		$this->icon->resize(100,100,false);
		$this->icon->cut(100,100);
	}
	
	public static function createSampleData() {
		
		ImageGridImage::getTable()->update();
		
		$item = ImageGridImage::query()->limit(1)->commit();
		if( $item )
			return;

		$images = array('1.jpg','2.png','3.jpg','4.png','5.jpg','6.jpg','7.jpg');
		
		for( $i=0; $i<20; $i++ ) {
			$item = new ImageGridImage();
			$item->title = 'Image '.($i+1);
			$item->icon->addExisting( DOM_MEDIA_DIR.'ImageGridIcons/'.$images[$i%7] );
			$item->save();
		}

		
	}
	
}
?>